package com.library.web.controller.api;

import com.library.common.core.controller.BaseController;
import com.library.common.core.page.TableDataInfo;
import com.library.common.utils.DateUtils;
import com.library.domain.BoBorrow;
import com.library.domain.MbSignRecord;
import com.library.service.IBoBorrowService;
import com.library.service.IMbSignRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 获取当前用户签到记录
 *
 * @author wanghongjie
 */
@Slf4j
@RestController
@RequestMapping("/api/signUp")
public class SignUpApiController extends BaseController {
    @Autowired
    private IMbSignRecordService mbSignRecordService;

    /**
     * 查询图书借阅列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MbSignRecord signRecord) {
        startPage();
        List<MbSignRecord> mbSignRecords = mbSignRecordService.selectMbSignRecordList(signRecord);
        return getDataTable(change(mbSignRecords));
    }

    private List<Map<String, String>> change(List<MbSignRecord> mbSignRecords) {
        List<Map<String, String>> list = new ArrayList<>(mbSignRecords.size());
        mbSignRecords.forEach(mbSignRecord -> {
            Map<String, String> map = new HashMap<>(16);
            map.put("signInTime", Objects.nonNull(mbSignRecord.getSignInTime()) ? DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, mbSignRecord.getSignInTime()) : "--");
            map.put("signIntegral", String.valueOf(mbSignRecord.getSignIntegral()));
            map.put("uninterruptedlySignNum", String.valueOf(mbSignRecord.getUninterruptedlySignNum()));
            map.put("id", String.valueOf(mbSignRecord.getId()));
            list.add(map);
        });
        return list;
    }
}
